<template>
  <div class="product-card" :class="cardClass" @click="handleClick">
    <div class="pictrue">
      <img :src="product.image || defaultImage" :alt="product.store_name" />
    </div>
    <div class="money acea-row" v-if="showPrice">
      <div>
        <span class="font-color">HK${{ product.price }}</span>
        <span class="y_money">HK${{ product.ot_price }}</span>
      </div>
      <div class="label font-color" v-if="product.checkCoupon">券</div>
    </div>
    <div class="name line2">{{ product.store_name }}</div>
    <div class="payment acea-row" v-if="showPayment">
      <span>{{ product.sales }}人付款</span>
      <span>{{ product.star }}分</span>
    </div>
    <!-- 插槽用於自定義內容 -->
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: "ProductCard",
  props: {
    product: {
      type: Object,
      required: true,
      default: () => ({}),
    },
    cardClass: {
      type: String,
      default: "",
    },
    showPrice: {
      type: Boolean,
      default: true,
    },
    showPayment: {
      type: Boolean,
      default: true,
    },
    defaultImage: {
      type: String,
      default: require("~/assets/images/no_goods.jpg"),
    },
  },
  methods: {
    handleClick() {
      this.$emit("click", this.product);
    },
  },
};
</script>

<style scoped lang="scss">
.product-card {
  width: 100%;
  min-height: 420px;
  background: $charcoal;
  padding: 0 16px 20px 16px;
  margin: 0;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  border-radius: 4px;
  overflow: hidden;

  &:hover {
    box-shadow: 0 0 0 1px rgba(200, 169, 126, 0.3),
      0 0 15px 5px rgba(200, 169, 126, 0.2);
    transform: translateY(-2px);
  }

  .pictrue {
    width: calc(100% + 32px);
    height: 260px;
    overflow: hidden;
    background: $ivory;
    margin: -16px -16px 10px -16px;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s ease;
    }
  }

  .money {
    margin: 12px 0;
    display: flex;
    align-items: center;
    gap: 16px;

    .font-color {
      font-size: 28px;
      font-weight: 700;
      color: $dark-gold;
      letter-spacing: -0.5px;
      transition: color 0.3s ease;
    }

    .y_money {
      color: $light-gray;
      font-size: 16px;
      text-decoration: line-through;
      font-weight: 500;
      margin-left: 16px;
      transition: color 0.3s ease;
    }

    .label {
      width: 24px;
      height: 24px;
      background: linear-gradient(135deg, $gold-light 0%, $dark-gold 100%);
      color: $pure-white;
      font-size: 12px;
      font-weight: 600;
      text-align: center;
      line-height: 24px;
      border-radius: 6px;
      box-shadow: 0 2px 8px rgba(139, 90, 43, 0.3);
      transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
    }
  }

  .name {
    margin: 0 0 16px 0;
    color: $ivory;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 1px;
    height: auto;
    min-height: 54px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.3s ease;
  }

  .payment {
    font-size: 14px;
    color: $ivory;
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    font-weight: 500;
    transition: color 0.3s ease;

    span {
      color: $gold-light;
    }

    span:last-child {
      color: $gold-light;
      font-weight: 600;
      transition: color 0.3s ease;

      &::after {
        content: "★";
        margin-left: 5px;
        color: $gold-light;
        transition: color 0.3s ease;
      }
    }
  }

  @media (max-width: 768px) {
    margin-right: 0;
    max-width: 100%;
    min-height: 320px;

    .pictrue {
      height: 160px;
    }

    .money .font-color {
      font-size: 20px;
    }

    .money .y_money {
      font-size: 12px;
      margin-left: 8px;
    }

    .money .label {
      width: 20px;
      height: 20px;
      font-size: 10px;
      line-height: 20px;
    }

    .name {
      font-size: 14px;
      min-height: 36px;
      margin-bottom: 8px;
    }

    .payment {
      font-size: 12px;
    }
  }
}
</style>
